<template>
  <div class="container">
    <h1>欢迎注册</h1>
    <div class="form-control">
      <input type="text" v-model="submitData.email" required autocomplete="off" />
      <label for="email">
        <span style="transition-delay: 0ms">请</span>
        <span style="transition-delay: 50ms">输</span>
        <span style="transition-delay: 100ms">入</span>
        <span style="transition-delay: 150ms">邮</span>
        <span style="transition-delay: 200ms">箱</span>
      </label>
    </div>
    <div class="form-control">
      <input type="text" v-model="submitData.username" required autocomplete="off" />
      <label for="email">
        <span style="transition-delay: 0ms">请</span>
        <span style="transition-delay: 50ms">输</span>
        <span style="transition-delay: 150ms">入</span>
        <span style="transition-delay: 200ms">用</span>
        <span style="transition-delay: 250ms">户</span>
        <span style="transition-delay: 300ms">名</span>
      </label>
    </div>
    <div class="form-control">
      <input
        type="password"
        id="password"
        v-model="submitData.password"
        autocomplete="new-password"
        required
      />
      <label for="password">
        <span style="transition-delay: 0ms">请</span>
        <span style="transition-delay: 50ms">输</span>
        <span style="transition-delay: 100ms">入</span>
        <span style="transition-delay: 150ms">密</span>
        <span style="transition-delay: 200ms">码</span>
      </label>
    </div>
    <div class="login-text">
      已有账号？去
      <a href="#" @click="toLogin">登录</a>
    </div>
    <button class="login-btn" @click.prevent.stop="login">注册</button>
  </div>
</template>

<script>
import api from "@/api"
import { mapActions } from "vuex"
export default {
  name: "register",
  data() {
    return {
      submitData: {},
      dialogVisible: true
    }
  },
  methods: {
    ...mapActions(["updateUserInfo", "updateToken", "closeApp", "getCollects"]),
    login() {
      var emailRe = /^([A-Za-z0-9_\-.])+@([A-Za-z0-9_\-.])+\.([A-Za-z]{2,4})$/
      if (emailRe.test(this.submitData.email)) {
        api
          .register(this.submitData.email, this.submitData.password, this.submitData.username)
          .then((result) => {
            if (result.data.status == 201) {
              this.dialogVisible = false
              this.$notify.success("您已注册成功，请登录")
            } else {
              this.$notify.success("您已注册过，请直接登录")
            }
          })
      } else {
        this.$notify.error("邮箱格式不正确")
      }
    },
    toLogin() {
      this.$emit("toLogin")
    }
  }
}
</script>

<style lang="less" scope>
@import url("https://fonts.googleapis.com/css?family=Muli&display=swap");
.container {
  position: relative;
  font-family: "Muli", sans-serif;
  padding: 20px 40px;
  background-color: rgba(0, 0, 0, 0.8);
  color: #fff;
  text-align: center;
  margin: 0 auto;
  height: 100%;
}
.container h1 {
  font-size: 24px;
  color: lightblue;
  margin-bottom: 30px;
}
.form-control {
  // width: 300px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.form-control label {
  font-size: 14px;
  color: rgba(202, 211, 200, 0.8);
  position: absolute;
  top: 15px;
}
.form-control input {
  width: 100%;
  background-color: transparent;
  margin-bottom: 30px;
  border: 0;
  padding: 15px 0;
  font-size: 18px;
  border-bottom: 2px solid #fff;
  color: lightblue;
}
.form-control input:focus {
  outline: none;
  caret-color: lightblue;
  border-bottom: 2px solid lightblue;
}
.login-btn {
  width: 100%;
  height: 50px;
  margin: 30px auto;
  padding: 5px;
  border-radius: 6px;
  border: none;
  background: lightblue;
  font-size: 20px;
  font-family: "Muli", sans-serif;
  transition: 0.5s;
}
.login-btn:hover {
  background-color: #55e6c1;
}
.register-text {
  margin: 5px;
}
.register-text a {
  text-decoration: none;
  color: lightblue;
}
/* animaition */
.form-control label span {
  display: inline-block;
  transition: 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.form-control input:focus + label span,
.form-control input:valid + label span {
  color: lightblue;
  transform: translateY(-30px);
}
.login-text {
  position: absolute;
  right: 40px;
}
.login-text {
  margin: 5px;
}
.login-text a {
  text-decoration: none;
  color: lightblue;
}
</style>
